package com.junmo.common.redis.manager;

import com.junmo.common.constant.RedisConstants;
import com.junmo.common.redis.utils.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Description:
 * @Author: zjj
 * @Date: 2022/7/11
 */
@Component
public class RedisCacheManager{

    @Autowired
    private RedisUtils redisUtils;

    /**
     * 获取短信验证码(key=SMS_CODE:type:mobile,value=code)
     *
     * @param type 验证码类型(DySmsEnum枚举中name属性)
     * @param mobile 手机号
     * @return
     */
    public Object getSmsCaptcha(String type,String mobile){
        return redisUtils.get(RedisConstants.SMS_CODE_PREFIX + type + ":" + mobile);
    }

    /**
     * 设置短信验证码(key=SMS_CODE:type:mobile,value=code)
     * @param type 验证码类型(DySmsEnum枚举中name属性)
     * @param mobile 手机号
     * @return
     */
    public boolean setSmsCaptcha(String type,String mobile,String code){
        return redisUtils.set(RedisConstants.SMS_CODE_PREFIX + type + ":" + mobile, code, RedisConstants.SMS_CODE_TIMEOUT);
    }

    /**
     * 移除redis中短信验证码(key=SMS_CODE:type:mobile,value=code)
     * @param type 验证码类型(DySmsEnum枚举中name属性)
     * @param mobile 手机号
     * @return
     */
    public void delSmsCaptcha(String type,String mobile){
        redisUtils.del(RedisConstants.SMS_CODE_PREFIX + type + ":" + mobile);
    }
}
